package org.sxp.modules.dataworks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.sxp.common.dto.DevelopJobDTO;
import org.sxp.common.exception.BusinessException;
import org.sxp.modules.datasource.entity.DatabaseDO;
import org.sxp.modules.datasource.service.DatabaseService;
import org.sxp.modules.dataworks.dao.DevelopDAO;
import org.sxp.modules.dataworks.dto.DevelopDTO;
import org.sxp.modules.dataworks.entity.DevelopDO;
import org.sxp.modules.dataworks.service.DevelopService;

/**
 * 数据开发
 * 所有的接口定义中显式的声明抛出异常（throws Exception）
 * @author 沈兴平
 * @date 2022/02/09
 */
@Service
public class DevelopServiceImpl extends ServiceImpl<DevelopDAO, DevelopDO>
        implements DevelopService{

    @Autowired
    DatabaseService databaseService;

    @Override
    public DevelopJobDTO buildJobParam(DevelopDO developDO){
        try{
            DevelopJobDTO developJobDTO = new DevelopJobDTO();
            DatabaseDO pubDb = databaseService.getById(developDO.getDevelopDb());
            if (pubDb == null) {
                throw new BusinessException("数据源不存在!!!");
            }
            developJobDTO.setJdbcUrl(pubDb.getUrl());
            developJobDTO.setUsername(pubDb.getUsername());
            developJobDTO.setPassword(pubDb.getPassword());
            developJobDTO.setSqlScript(developDO.getSqlScript());
            return developJobDTO;
        }catch (Exception ex){
            log.error(ex.getMessage(), ex);
        }
        return null;
    }
}
